package com.weiqiao.report.distributior.rest;

import com.weiqiao.aop.log.Log;
import com.weiqiao.report.distributior.Service.IUserReportService;
import com.weiqiao.report.distributior.domain.dto.UserReportEntityDTO;
import com.weiqiao.report.distributior.domain.vo.UserReportVO;
import com.weiqiao.utils.FileUtil;
import com.weiqiao.utils.PageUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/report")
public class UserReportController {

    @Autowired
    private IUserReportService userReportService;

    @Log("分销员业绩统计")
    @GetMapping("/user-list")
    public ResponseEntity getOrderList(UserReportVO vo, Pageable pageable) {
        List<UserReportEntityDTO> list = userReportService.getUserList(vo, pageable);
        int count = userReportService.countNum(vo);
        return new ResponseEntity(PageUtil.toPage(list, count), HttpStatus.OK);
    }

    @Log("分销员业绩统计导出")
    @GetMapping("/export-user-list")
    public void exportOrderList(UserReportVO vo, HttpServletResponse response) throws IOException {
        List<Map<String, Object>> list = userReportService.expportUserList(vo);
        FileUtil.downloadExcel(list, response);
    }
}
